package com.kingdee.pda.ui.widget;

import android.content.Context;
import android.support.annotation.ColorInt;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.annotation.StyleRes;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import com.kingdee.pda.R;


/**
 * @author LiJiaJian
 * @date 2016/7/18 17:43
 */
public class CenterTitleToolbar extends Toolbar {

    private TextView mCenterTitleView;

    public CenterTitleToolbar(Context context) {
        super(context);
        initCenterTitleView(context);
    }

    public CenterTitleToolbar(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initCenterTitleView(context);
    }

    public CenterTitleToolbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initCenterTitleView(context);
    }

    /**
     * 初始化中间标题
     *
     * @param context
     */
    private void initCenterTitleView(Context context) {
        super.setTitle("");
        View.inflate(context, R.layout.widget_toolbar_title, this);
        mCenterTitleView = (TextView) findViewById(R.id.tv_toolbar_title);
    }

    @Override
    public void setTitle(@StringRes int resId) {
        if (resId > 0) {
            mCenterTitleView.setText(resId);
        }
    }

    @Override
    public void setTitle(CharSequence title) {
        mCenterTitleView.setText(title);
    }

    @Override
    public void setTitleTextAppearance(Context context, @StyleRes int resId) {
        if (resId > 0) {
            mCenterTitleView.setTextAppearance(context, resId);
        }
    }

    /**
     * 此函数已废除
     */
    @Deprecated
    @Override
    public boolean isTitleTruncated() {
        return false;
    }

    @Override
    public void setTitleTextColor(@ColorInt int color) {
        mCenterTitleView.setTextColor(color);
    }
}
